package com.changil.nowonchangil.api;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import net.coobird.thumbnailator.Thumbnails;

import com.changil.nowonchangil.controller.ServiceController;
import com.changil.nowonchangil.dto.Article;
import com.changil.nowonchangil.dto.ArticleList;
import com.changil.nowonchangil.dto.InsertedId;

@Path("/images")
public class ImageApi {
	private ServiceController controller = new ServiceController();

	public void SetScoreService(ServiceController controller) {
		this.controller = controller;
	}

	@GET
	@Path("/thumbnail")
	@Produces("image/jpeg")
	public Image getFile(@QueryParam("source") String source,
			@QueryParam("width") int width) {
		URL url = null;
		try {
			url = new URL(source);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		BufferedImage thumbnail = null;
		try {
			thumbnail = Thumbnails.of(url).size(width, width).asBufferedImage();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return thumbnail;
	}
}
